package com.wenan.ui.controls.dateChooser
{
	import mx.controls.DateChooser;
	import mx.core.mx_internal;

	public class MonthPanel extends DateChooserExt
	{
		private var _grid:MonthGrid = new MonthGrid();
		private var timeNow:Date = new Date();
		public function MonthPanel()
		{
			super();
		}
		
		public function get grid():MonthGrid
		{
			return _grid;
		}

		override protected function createChildren():void
		{
			super.createChildren();
			this.removeChild(this.mx_internal::dateGrid);
			this.mx_internal::fwdMonthButton.visible = false;
			this.mx_internal::backMonthButton.visible = false;
			grid.addEventListener(DateEvent.SELECTEDDATE, selectedDateHandler);
			grid.y = 38;
			grid.x = 8;
			grid.percentWidth = 100;
			grid.percentHeight = 100;
			this.addChild(grid);
		}
		
		private function selectedDateHandler(event:DateEvent):void
		{
//			this.mx_internal::yearDisplay.text = timeNow.fullYear.toString();
			this.mx_internal::monthDisplay.text = "";
			dispatchEvent(new DateEvent(DateEvent.SELECTEDDATE, event.date));
		}
		
		override protected function updateDisplayList(unscaledWidth:Number,
													  unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			this.mx_internal::monthDisplay.text = "";
		}
		
		override public  function set selectedDate(value:Date):void
		{
			this.mx_internal::yearDisplay.text = value.fullYear;
			var curr:int = value.month;
			grid.selectedMonth(curr);
			grid.dispatchEvent(new DateEvent(DateEvent.SELECTEDDATE, DateUtil.convert(curr)));
		}
	}
}